﻿(function ($, undefined) {
    $.widget("ui.comboselect", {
        options: undefined,

        _create: function () {
            if (this.options != undefined)
                this._refreshValue();
        },

        destroy: function () { },

        
        _setOption: function (key, value) {

            if (key === "textbuttom") {
                this.options.textButtom = value;
            } else {
                return;
            }
            $.Widget.prototype._setOption.apply(this, arguments);
        },

        _refreshValue: function () {
            var container = this.element;
            container.addClass('comboSelect');
            container.addClass('close');
            var body = container.find(' > div');
            var buttom = container.find(' > a');

            if (this.options.textButtom) {
                buttom.html(this.options.textButtom);
            }

            body.hide();

            buttom.click(function () {
                body.toggle();
                if (body.is(':visible')) {
                    container.addClass('open');
                } else {
                    container.addClass('close');
                }
            }).attr('href', 'javascript:void(0);')


        },

        close : function(){ 
            var container = this.element;
            var body = container.find(' > div');
            body.hide();
            container.addClass('close');
        },
    });

    $.extend($.ui.comboselect, {
        version: "1.0.0"
    });

})(jQuery);